package com.ljf.authority.web;

import com.ljf.authority.dto.command.AuthorityBaseApiTabulationActivationCommand;
import com.ljf.authority.dto.command.AuthorityBaseApiTabulationCommand;
import com.ljf.authority.dto.command.AuthorityBaseApiTabulationMenuCommand;
import com.ljf.authority.dto.command.AuthorityBaseApiTabulationTemplateCommand;
import com.ljf.authority.dto.query.AuthorityBaseApiTabulationQuery;
import com.ljf.authority.service.IAuthorityBaseApiTabulationService;
import com.ljf.authority.vo.AuthorityBaseApiTabulationVO;
import com.ljf.common.exception.ServiceException;
import com.ljf.common.result.ResultModel;
import com.ljf.common.validation.AddGroup;
import com.ljf.common.validation.UpdateGroup;
import com.ljf.common.web.BasisController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * API列表定义  控制器
 *
 * @author LJF
 * @since 2025-05-27
 */
@RestController
@RequestMapping("/authority/base/api_tabulation")
@Api(value = "API列表定义接口", tags = "API列表定义接口")
public class AuthorityBaseApiTabulationController extends BasisController<IAuthorityBaseApiTabulationService, AuthorityBaseApiTabulationQuery, AuthorityBaseApiTabulationVO, AuthorityBaseApiTabulationCommand> {

    @PostMapping("/batch/template")
    @ApiOperation(value = "通过模板批量新增API列表定义接口")
    public ResultModel addBatchByTemplate(@RequestBody @Validated(AddGroup.class) AuthorityBaseApiTabulationTemplateCommand command) throws ServiceException {
        return service.addBatchByTemplate(command);
    }

    @PutMapping("/activation")
    @ApiOperation(value = "修改API列表定义激活状态接口")
    public ResultModel editActivation(@RequestBody @Validated(UpdateGroup.class) AuthorityBaseApiTabulationActivationCommand command) throws ServiceException {
        return service.editActivation(command);
    }

    @PutMapping("/menu")
    @ApiOperation(value = "修改API列表定义关联菜单接口")
    public ResultModel editMenu(@RequestBody @Validated(UpdateGroup.class) AuthorityBaseApiTabulationMenuCommand command) throws ServiceException {
        return service.editMenu(command);
    }

    @GetMapping("/info")
    @ApiOperation(value = "查询API列表表单信息接口")
    public ResultModel queryInfo(String url, Integer method) throws ServiceException {
        return service.queryInfo(url, method);
    }

    @GetMapping("/template")
    @ApiOperation(value = "查询API列表模板接口")
    public ResultModel queryTemplate(String tableName) throws ServiceException {
        return service.queryTemplate(tableName);
    }

    @GetMapping("/menu/{id}")
    @ApiOperation(value = "根据ID查询API列表关联菜单接口")
    public ResultModel queryMenuById(@PathVariable Long id) throws ServiceException {
        return service.queryMenuById(id);
    }

}